package chapter06

object Test07_Inherit {
  def main(args: Array[String]): Unit = {
    val student1 = new Student7("alice", 8)
    println("===============================================")
    val student2 = new Student7("alice", 18, "123456")
    println("===============================================")
    val teacher = new Teacher7
    teacher.printInfo()

    def personInfo(person7: Person7) = {
      person7.printInfo()
    }

    personInfo(student2)
    personInfo(teacher)
  }
}


//定义一个父类
class Person7() {
  var name: String = _
  var age: Int = _
  println("1.父类的主构造器被调用")

  def this(name: String, age: Int) {
    this
    println("2.父类的辅助构造器调用")
    this.name = name
    this.age = age
  }

  def printInfo() = {
    println(s"Person: $name,$age")
  }
}

class Student7(name: String, age: Int) extends Person7(name, age) {
  var stuNo: String = _
  println("3.子类的主构造器被调用")

  def this(name: String, age: Int, stuNo: String) {
    this(name, age)
    println("4.子类的辅助构造器被调用")
    this.stuNo = stuNo
  }

  override def printInfo() = {
    println(s"Student: $name $age $stuNo")
  }


}


class Teacher7 extends Person7 {
  override def printInfo(): Unit = {
    println(s"Teachers")
  }
}

